package gui.edit.components.dialogs;

import gui.IHM;
import gui.visu.listeners.ListenerComponentClosingParentDialog;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import tuio.components.LabelTouch;
import tuio.components.TextAreaTouch;

import data.visu.utils.ImageLoader;


/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class JDialogHelpButton extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8845638016624445385L;

	private String infos, imageURL;

	private TextAreaTouch infosArea;

	public JDialogHelpButton(IHM parent, String title, boolean modal, String infos, String imageURL) {
		super(parent, title, modal);

		this.infos=infos;
		this.imageURL = imageURL;

		setLocationRelativeTo(null);
		setUndecorated(true);
		setResizable(false);
		initComponent();
		pack();
	}

	private void initComponent() {
		this.getContentPane().setLayout(new BorderLayout());

		JPanel content = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.insets=new Insets(3, 3, 3, 3);
		c.gridx=0;
		c.gridy=0;
		c.fill=GridBagConstraints.BOTH;

		infosArea = new TextAreaTouch(8,20);
		ListenerComponentClosingParentDialog listener = new ListenerComponentClosingParentDialog(this);
		infosArea.addMouseListener(listener);
		infosArea.setText(infos);
		infosArea.setEditable(false);
		infosArea.setBorder(BorderFactory.createEtchedBorder());
		infosArea.setLineWrap(true);
		JScrollPane scrollPaneInfos = new JScrollPane(infosArea);
		content.add(scrollPaneInfos,c);

		if(imageURL!=null){
			c.gridy+=1;
			LabelTouch imageLabel = new LabelTouch(ImageLoader.createImageIcon(imageURL));
			imageLabel.addMouseListener(listener);
			imageLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			content.add(imageLabel, c);
		}

		this.getContentPane().add(content, BorderLayout.CENTER);
	}

}
